package com.cjm.one.goods.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.cjm.one.common.result.Result;
import com.cjm.one.common.utils.AuthCustomerContextHolder;
import com.cjm.one.goods.service.GoodsInfoService;
import com.cjm.one.model.goods.dto.GoodsInfoDto;
import com.cjm.one.model.goods.entity.GoodsInfo;
import com.cjm.one.model.goods.vo.GoodsInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/goods/info")
@Slf4j
@Tag(name = "2商品信息")
public class GoodsInfoController {
    @Resource
    private GoodsInfoService goodsInfoService;
    @GetMapping("/list")
    @Operation(summary = "分页查询")
    public Result<Page<GoodsInfo>> pageList(@RequestParam(name = "current") Long current,
                                            @RequestParam(name = "size") Long size,
                                            @RequestParam(name = "name",required = false) String name,
                                            @RequestParam(name = "categoryId", required = false) Long categoryId){
        Page<GoodsInfoVo> page = new Page<>(current, size);



        return Result.ok(goodsInfoService.pageList(page,name,categoryId));
    }


    @GetMapping("/list/batch/{ids}")
    @Operation(summary = "批量查询")
    public Result<List<GoodsInfo>> listBatch(@PathVariable(name = "ids") Long[] ids){
        List<GoodsInfo>  goodsInfoPage =  goodsInfoService.listBatch(ids);
        return Result.ok(goodsInfoPage);
    }
    @GetMapping("/{id}")
    @Operation(summary = "根据id查询")
    public Result<GoodsInfoVo> getById(@PathVariable("id") Long id){
        return Result.ok(goodsInfoService.getGoodsInfoById(id));
    }
    @PostMapping
    @Operation(summary = "新增")
    public Result<Boolean> save(@RequestBody GoodsInfoDto goodsInfoDto){
        return Result.ok(goodsInfoService.saveGoodsInfo(goodsInfoDto));
    }
    @PutMapping
    @Operation(summary = "修改")
    public Result<Boolean> update(@RequestBody GoodsInfoDto goodsInfoDto){
        return Result.ok(goodsInfoService.updateGoodsInfoById(goodsInfoDto));
    }
    @DeleteMapping("/{id}")
    @Operation(summary = "根据id删除")
    public Result<Boolean> remove(@PathVariable("id") Long id){
        return Result.ok(goodsInfoService.removeGoodsInfoById(id));
    }


}
